package es.uca.gii.csi.Shield.data;
import java.util.Calendar;
import java.util.Date;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

import es.uca.gii.csi.Shield.util.Config;

public class Data 
{
	public static String getPropertiesUrl() { return "./src/db.properties"; }
	public static Connection Connection() throws Exception 
	{
		try 
		{
			Properties properties = Config.Properties(getPropertiesUrl());
			return DriverManager.getConnection(
					properties.getProperty("jdbc.url"),
					properties.getProperty("jdbc.username"),
					properties.getProperty("jdbc.password"));
		}catch (Exception ee) { throw ee; }
	}
	
	
	public static String String2Sql(String s, boolean bAddWildcards)
	{
		return s.replace("'", "''");
	}
			
	public static int Boolean2Sql(Boolean b)
	{
		return b ? 1 : 0;
	}
	
	public static java.sql.Date DateTime2Sql(Calendar dt)
	{
		Date tFecha = dt.getTime();
		java.sql.Date fechaSql = new java.sql.Date(tFecha.getTime());
		
		return fechaSql;
	}
	
	 public static String LastId(Connection con) throws Exception
	 {
		 try 
			{
				Properties properties = Config.Properties(getPropertiesUrl());
				return properties.getProperty("jdbc.lastIdSentence");
			}catch (Exception ee) { throw ee; }
	 }
	
}
